<script setup>
import { ref, reactive } from 'vue'
import { handleAlarm } from '@/assets/api/api'
import { showMsg, formatStamp } from '@/assets/js/utils'

const props = defineProps({
    visible: {
        type: Boolean,
        required: true,
    },
    deviceClassId: {
        type: String,
        default: '',
    },
    deviceClassify: {
        type: String,
        default: '',
    },
    activeData: {
        type: Object,
        default() {
            return {}
        },
    },
})
const emits = defineEmits(['update:visible', 'success'])
function closeAction() {
    emits('update:visible', false)
}
const handleForm = reactive({
    batchHandle: false,
})
const formRef = ref()
const submitAction = () => {
    formRef.value.validate((valid, fields) => {
        if (valid) {
            handleForm.handleTime = formatStamp(
                +new Date(),
                'yyy-MM-dd hh:mm:ss'
            )
            handleForm.id = props.activeData.id
            handleAlarm(handleForm).then(() => {
                showMsg('处置成功')
                closeAction()
                emits('success')
            })
        } else {
            console.log('error submit!', fields)
        }
    })
}
</script>
<template>
    <el-dialog
        :model-value="visible"
        title="导入设备"
        width="600px"
        :draggable="true"
        @close="closeAction"
    >
        <el-form ref="formRef" :model="handleForm" label-width="120px">
            <el-form-item
                label="信息确认："
                prop="infoConfirm"
                :rules="[
                    {
                        required: true,
                        message: '请选择',
                    },
                ]"
            >
                <el-radio-group v-model="handleForm.infoConfirm">
                    <el-radio label="1">报警</el-radio>
                    <el-radio label="2">误报</el-radio>
                    <el-radio label="3">测试</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="批处理：">
                <el-checkbox v-model="handleForm.batchHandle"
                    >是否批处理改设备警情</el-checkbox
                >
            </el-form-item>
            <el-form-item
                label="处置人员："
                prop="handlePerson"
                :rules="[
                    {
                        required: true,
                        message: '请输入处置人员',
                    },
                ]"
            >
                <el-input
                    placeholder="请输入"
                    v-model.trim="handleForm.handlePerson"
                ></el-input>
            </el-form-item>
            <el-form-item label="备注：">
                <el-input
                    placeholder="请输入"
                    type="textarea"
                    v-model.trim="handleForm.handleRemark"
                ></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="closeAction">取消</el-button>
                <el-button type="primary" @click="submitAction">
                    处置
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>
<style lang="scss" scoped></style>
